
Option Strict On

Imports cmplib01

' this control accepts campaign game data as a property and allows the viewing of the objects
' with some filtering. It also can return the object selected
' objects that do not have an icon (rule, resource and order) use icons 0, 1 and 2 respectively, while
' objects that do have an icon use their own icon.

Public Class ctlObjectDisplay
    Inherits System.Windows.Forms.UserControl

    Private c_Module As String = "ctlObjectDisplay"

    Private filterParam As Int16 = 63  ' marks items as they are filtered, starting with NONE being filtered
    Private iconId As Int32    ' to assign the correct icon with the correct object

    Private Const SHOWOBJECTIVES As Int16 = 1
    Private Const SHOWUNITS As Int16 = 2
    Private Const SHOWTOKENS As Int16 = 4
    Private Const SHOWRULES As Int16 = 8
    Private Const SHOWRESOURCES As Int16 = 16
    'Private Const SHOWORDERS As Int16 = 32
    ' icon indices
    Private Const RULESICON As Int16 = 0
    Private Const RESOURCESICON As Int16 = 1
    Private Const ORDERSICON As Int16 = 2
    Friend WithEvents pnlDefObjClient As System.Windows.Forms.Panel
    Friend WithEvents lstObjects As System.Windows.Forms.ListView
    Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents pgdItem As System.Windows.Forms.PropertyGrid

    Private mvarCGD As cmplib01.CampaignerGameData

    'Private itemKeyList() As String       ' these two keep track of whats in the listview so it can be returned
    'Private itemKeyListIndex As Integer
    'Private itemList As Collection

    Public Event ItemSelected(ByRef obj As Object, ByRef objectType As CampaignerObjectType_cot)
    Public Event ItemDoubleClicked(ByRef obj As Object, ByRef objectType As CampaignerObjectType_cot)


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ctlObjectDisplay))
        Me.imlFilterIcons = New System.Windows.Forms.ImageList(Me.components)
        Me.chkFilterObjectives = New System.Windows.Forms.CheckBox
        Me.chkFilterUnits = New System.Windows.Forms.CheckBox
        Me.chkFilterTokens = New System.Windows.Forms.CheckBox
        Me.chkFilterRules = New System.Windows.Forms.CheckBox
        Me.chkFilterResources = New System.Windows.Forms.CheckBox
        Me.chkFilterIndicators = New System.Windows.Forms.CheckBox
        Me.lblFilters = New System.Windows.Forms.Label
        Me.pnlDefObjClient = New System.Windows.Forms.Panel
        Me.lstObjects = New System.Windows.Forms.ListView
        Me.Splitter1 = New System.Windows.Forms.Splitter
        Me.pgdItem = New System.Windows.Forms.PropertyGrid
        Me.pnlDefObjClient.SuspendLayout()
        Me.SuspendLayout()
        '
        'imlFilterIcons
        '
        Me.imlFilterIcons.ImageStream = CType(resources.GetObject("imlFilterIcons.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.imlFilterIcons.TransparentColor = System.Drawing.Color.White
        Me.imlFilterIcons.Images.SetKeyName(0, "")
        Me.imlFilterIcons.Images.SetKeyName(1, "")
        Me.imlFilterIcons.Images.SetKeyName(2, "")
        Me.imlFilterIcons.Images.SetKeyName(3, "")
        Me.imlFilterIcons.Images.SetKeyName(4, "")
        Me.imlFilterIcons.Images.SetKeyName(5, "")
        '
        'chkFilterObjectives
        '
        Me.chkFilterObjectives.Appearance = System.Windows.Forms.Appearance.Button
        Me.chkFilterObjectives.Checked = True
        Me.chkFilterObjectives.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkFilterObjectives.Image = CType(resources.GetObject("chkFilterObjectives.Image"), System.Drawing.Image)
        Me.chkFilterObjectives.Location = New System.Drawing.Point(0, 16)
        Me.chkFilterObjectives.Name = "chkFilterObjectives"
        Me.chkFilterObjectives.Size = New System.Drawing.Size(40, 24)
        Me.chkFilterObjectives.TabIndex = 3
        '
        'chkFilterUnits
        '
        Me.chkFilterUnits.Appearance = System.Windows.Forms.Appearance.Button
        Me.chkFilterUnits.Checked = True
        Me.chkFilterUnits.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkFilterUnits.Image = CType(resources.GetObject("chkFilterUnits.Image"), System.Drawing.Image)
        Me.chkFilterUnits.Location = New System.Drawing.Point(40, 16)
        Me.chkFilterUnits.Name = "chkFilterUnits"
        Me.chkFilterUnits.Size = New System.Drawing.Size(40, 24)
        Me.chkFilterUnits.TabIndex = 4
        '
        'chkFilterTokens
        '
        Me.chkFilterTokens.Appearance = System.Windows.Forms.Appearance.Button
        Me.chkFilterTokens.Checked = True
        Me.chkFilterTokens.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkFilterTokens.Image = CType(resources.GetObject("chkFilterTokens.Image"), System.Drawing.Image)
        Me.chkFilterTokens.Location = New System.Drawing.Point(160, 16)
        Me.chkFilterTokens.Name = "chkFilterTokens"
        Me.chkFilterTokens.Size = New System.Drawing.Size(40, 24)
        Me.chkFilterTokens.TabIndex = 5
        '
        'chkFilterRules
        '
        Me.chkFilterRules.Appearance = System.Windows.Forms.Appearance.Button
        Me.chkFilterRules.Checked = True
        Me.chkFilterRules.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkFilterRules.Image = CType(resources.GetObject("chkFilterRules.Image"), System.Drawing.Image)
        Me.chkFilterRules.Location = New System.Drawing.Point(80, 16)
        Me.chkFilterRules.Name = "chkFilterRules"
        Me.chkFilterRules.Size = New System.Drawing.Size(40, 24)
        Me.chkFilterRules.TabIndex = 6
        '
        'chkFilterResources
        '
        Me.chkFilterResources.Appearance = System.Windows.Forms.Appearance.Button
        Me.chkFilterResources.Checked = True
        Me.chkFilterResources.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkFilterResources.Image = CType(resources.GetObject("chkFilterResources.Image"), System.Drawing.Image)
        Me.chkFilterResources.Location = New System.Drawing.Point(120, 16)
        Me.chkFilterResources.Name = "chkFilterResources"
        Me.chkFilterResources.Size = New System.Drawing.Size(40, 24)
        Me.chkFilterResources.TabIndex = 7
        '
        'chkFilterIndicators
        '
        Me.chkFilterIndicators.Appearance = System.Windows.Forms.Appearance.Button
        Me.chkFilterIndicators.Checked = True
        Me.chkFilterIndicators.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkFilterIndicators.Image = CType(resources.GetObject("chkFilterIndicators.Image"), System.Drawing.Image)
        Me.chkFilterIndicators.Location = New System.Drawing.Point(200, 16)
        Me.chkFilterIndicators.Name = "chkFilterIndicators"
        Me.chkFilterIndicators.Size = New System.Drawing.Size(40, 24)
        Me.chkFilterIndicators.TabIndex = 8
        '
        'lblFilters
        '
        Me.lblFilters.AutoSize = True
        Me.lblFilters.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblFilters.ForeColor = System.Drawing.Color.Navy
        Me.lblFilters.Location = New System.Drawing.Point(0, -2)
        Me.lblFilters.Name = "lblFilters"
        Me.lblFilters.Size = New System.Drawing.Size(72, 13)
        Me.lblFilters.TabIndex = 9
        Me.lblFilters.Text = "Defined Items"
        '
        'pnlDefObjClient
        '
        Me.pnlDefObjClient.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pnlDefObjClient.Controls.Add(Me.lstObjects)
        Me.pnlDefObjClient.Controls.Add(Me.Splitter1)
        Me.pnlDefObjClient.Controls.Add(Me.pgdItem)
        Me.pnlDefObjClient.Location = New System.Drawing.Point(3, 46)
        Me.pnlDefObjClient.Name = "pnlDefObjClient"
        Me.pnlDefObjClient.Size = New System.Drawing.Size(236, 254)
        Me.pnlDefObjClient.TabIndex = 10
        '
        'lstObjects
        '
        Me.lstObjects.Dock = System.Windows.Forms.DockStyle.Fill
        Me.lstObjects.Location = New System.Drawing.Point(0, 0)
        Me.lstObjects.MultiSelect = False
        Me.lstObjects.Name = "lstObjects"
        Me.lstObjects.Size = New System.Drawing.Size(236, 86)
        Me.lstObjects.SmallImageList = Me.imlFilterIcons
        Me.lstObjects.TabIndex = 7
        Me.lstObjects.UseCompatibleStateImageBehavior = False
        Me.lstObjects.View = System.Windows.Forms.View.List
        '
        'Splitter1
        '
        Me.Splitter1.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.Splitter1.Location = New System.Drawing.Point(0, 86)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(236, 3)
        Me.Splitter1.TabIndex = 6
        Me.Splitter1.TabStop = False
        '
        'pgdItem
        '
        Me.pgdItem.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.pgdItem.Location = New System.Drawing.Point(0, 89)
        Me.pgdItem.Name = "pgdItem"
        Me.pgdItem.Size = New System.Drawing.Size(236, 165)
        Me.pgdItem.TabIndex = 2
        '
        'ctlObjectDisplay
        '
        Me.Controls.Add(Me.pnlDefObjClient)
        Me.Controls.Add(Me.lblFilters)
        Me.Controls.Add(Me.chkFilterIndicators)
        Me.Controls.Add(Me.chkFilterResources)
        Me.Controls.Add(Me.chkFilterRules)
        Me.Controls.Add(Me.chkFilterTokens)
        Me.Controls.Add(Me.chkFilterUnits)
        Me.Controls.Add(Me.chkFilterObjectives)
        Me.Name = "ctlObjectDisplay"
        Me.Size = New System.Drawing.Size(247, 303)
        Me.pnlDefObjClient.ResumeLayout(False)
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

#Region "Listing to view"

    Public Sub ListItems()
        ' order of list is:
        ' objectives, units, tokens, rules, resources, orders

        ' clear stuff
        Try
            lstObjects.Clear()

            If chkFilterObjectives.Checked = True Then ListObjectives()
            If chkFilterUnits.Checked = True Then ListUnits()
            If chkFilterTokens.Checked = True Then ListTokens()
            If chkFilterRules.Checked = True Then ListRules()
            If chkFilterResources.Checked = True Then ListResources()
            'If chkFilterOrders.Checked = True Then ListOrders()
            If chkFilterIndicators.Checked = True Then ListIndicators()
        Catch ex As Exception
            Debug.WriteLine("Error!! '" & ex.Message & "' received in ctlObjectDisplay.ListItems")
        End Try
    End Sub

    Private Sub ListIndicators()
        Try
            If mvarCGD Is Nothing Then Exit Sub

            If mvarCGD.Indicators Is Nothing Then mvarCGD.Indicators = New Hashtable

            For Each indKey As String In mvarCGD.Indicators.Keys
                Dim indie As Indicator = DirectCast(mvarCGD.Indicators.Item(indKey), Indicator)
                Dim citem As New CampaignerListViewItem
                citem.Text = indie.indicatorName
                citem.obj = indie
                citem.CampaignerObjectType = CampaignerObjectType_cot.indicator
                citem.ImageIndex = 5
                lstObjects.Items.Add(citem)

            Next
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub ListObjectives()
        Dim objType As cmplib01.ObjectiveType
        If mvarCGD Is Nothing Then Exit Sub
        Try
            For Each objType In mvarCGD.ObjectiveTypes
                Dim citem As New CampaignerListViewItem
                citem.Text = objType.Name
                citem.obj = objType
                citem.CampaignerObjectType = CampaignerObjectType_cot.objective
                citem.ImageIndex = 0
                lstObjects.Items.Add(citem)
            Next
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

        'Dim de As DictionaryEntry
        'Dim skey As String

        'For Each de In mvarCGD.ObjectiveTypes
        '    skey = de.Key.ToString

        '    Try
        '        objType = CType(mvarCGD.ObjectiveTypes.Item(skey), cmplib01.ObjectiveType)
        '    Catch ex As Exception
        '        MsgBox("An error was encountered in objective types hashtable.", MsgBoxStyle.Exclamation, "Error")
        '        Exit For
        '    End Try

        '    Dim citem As New CampaignerListViewItem
        '    citem.Text = objType.Name
        '    citem.obj = objType
        '    citem.CampaignerObjectType = CampaignerObjectType_cot.objective
        '    citem.ImageIndex = 0

        '    lstObjects.Items.Add(citem)
        'Next

    End Sub

    Private Sub ListUnits()
        Dim unit As cmplib01.UnitType
        If mvarCGD Is Nothing Then Exit Sub

        Try
            For Each unit In mvarCGD.UnitTypes
                Dim citem As New CampaignerListViewItem
                citem.Text = unit.TypeName
                citem.obj = unit
                citem.CampaignerObjectType = CampaignerObjectType_cot.unit
                citem.ImageIndex = 1
                lstObjects.Items.Add(citem)
            Next
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

        'Dim de As DictionaryEntry
        'Dim sKey As String

        'For Each de In mvarCGD.UnitTypes
        '    sKey = de.Key.ToString

        '    Try
        '        unit = CType(mvarCGD.UnitTypes(sKey), cmplib01.UnitType)
        '    Catch
        '        MsgBox("An error was encountered in unit types hashtable.", MsgBoxStyle.Exclamation, "Error")
        '        Exit For
        '    End Try

        '    Dim citem As New CampaignerListViewItem
        '    citem.Text = unit.Name
        '    citem.obj = unit
        '    citem.CampaignerObjectType = CampaignerObjectType_cot.unit
        '    citem.ImageIndex = 1

        '    lstObjects.Items.Add(citem)
        'Next

    End Sub

    Private Sub ListTokens()
        Dim tok As cmplib01.TokenType
        Dim de As DictionaryEntry
        Dim sKey As String

        For Each de In mvarCGD.TokenTypes
            sKey = de.Key.ToString
            'itemKeyList(itemKeyListIndex) = sKey
            'itemKeyListIndex += 1
            Try
                tok = CType(mvarCGD.TokenTypes(sKey), cmplib01.TokenType)

                Dim citem As New CampaignerListViewItem
                citem.Text = tok.tokenTypeName
                citem.CampaignerObjectType = CampaignerObjectType_cot.token
                citem.obj = tok
                citem.ImageIndex = 2

                lstObjects.Items.Add(citem)
            Catch
                MsgBox("An error was encountered in token types hashtable.", MsgBoxStyle.Exclamation, "Error")
            End Try
        Next

    End Sub

    Private Sub ListRules()
        Dim de As New DictionaryEntry()
        Dim sKey As String
        Dim rulType As cmplib01.RuleType

        If mvarCGD Is Nothing Then Exit Sub

        Try
            For Each de In mvarCGD.RuleTypes_g.HT
                sKey = de.Key.ToString
                rulType = mvarCGD.RuleTypes_g.Item(sKey)

                Dim citem As New CampaignerListViewItem
                citem.Text = rulType.RuleName
                citem.obj = rulType
                citem.CampaignerObjectType = CampaignerObjectType_cot.rule
                citem.ImageIndex = 3

                lstObjects.Items.Add(citem)
            Next

        Catch ex As Exception
            HandleException("ctlObjectDisplay", ex)
        End Try

    End Sub

    Private Sub ListResources()
        Dim de As DictionaryEntry
        Dim sKey As String
        Dim rest As cmplib01.ResourceType

        For Each de In mvarCGD.ResourceTypes_g.HT
            sKey = de.Key.ToString
            rest = mvarCGD.ResourceTypes_g.Item(sKey)

            Dim citem As New CampaignerListViewItem
            citem.Text = rest.ResourceName
            citem.obj = rest
            citem.CampaignerObjectType = CampaignerObjectType_cot.resource
            citem.ImageIndex = 4

            lstObjects.Items.Add(citem)
        Next

    End Sub

    Private Sub ListOrders()
        Dim de As DictionaryEntry
        Dim sKey As String
        Dim ord As cmplib01.OrderType

        For Each de In mvarCGD.Orders_g.HT
            sKey = de.Key.ToString
            ord = mvarCGD.Orders_g.Item(sKey)

            Dim citem As New CampaignerListViewItem
            citem.Text = ord.OrderName
            citem.obj = ord
            citem.CampaignerObjectType = CampaignerObjectType_cot.order
            citem.ImageIndex = 5

            lstObjects.Items.Add(citem)
        Next

    End Sub

#End Region

#Region "Properties"

    Public Property ShowLowerGrid() As Boolean
        Get
            Return pgdItem.Visible
        End Get
        Set(ByVal value As Boolean)
            pgdItem.Visible = value
        End Set
    End Property

    Public WriteOnly Property campaignerGameData() As cmplib01.CampaignerGameData
        Set(ByVal Value As cmplib01.CampaignerGameData)
            mvarCGD = Value
        End Set
    End Property

    Public ReadOnly Property DisplayedObject() As CampaignerListViewItem
        Get
            Try
                If lstObjects.SelectedItems.Count = 0 Then Return New CampaignerListViewItem
                Return DirectCast(lstObjects.SelectedItems(0), CampaignerListViewItem)
            Catch ex As Exception
                Debug.WriteLine("Error!! '" & ex.Message & "' in ctlObjectDisplay.DisplayedObject")
                Return New CampaignerListViewItem
            End Try
        End Get
    End Property
#End Region

    Private Sub ctlObjectDisplay_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' load up the correct icons
        chkFilterObjectives.Image = imlFilterIcons.Images(0)
        chkFilterUnits.Image = imlFilterIcons.Images(1)
        chkFilterTokens.Image = imlFilterIcons.Images(2)
        chkFilterRules.Image = imlFilterIcons.Images(3)
        chkFilterResources.Image = imlFilterIcons.Images(4)
        chkFilterIndicators.Image = imlFilterIcons.Images(5)

    End Sub

    Friend WithEvents imlFilterIcons As System.Windows.Forms.ImageList
    Friend WithEvents lblFilters As System.Windows.Forms.Label
    Friend WithEvents chkFilterIndicators As System.Windows.Forms.CheckBox
    Friend WithEvents chkFilterResources As System.Windows.Forms.CheckBox
    Friend WithEvents chkFilterRules As System.Windows.Forms.CheckBox
    Friend WithEvents chkFilterTokens As System.Windows.Forms.CheckBox
    Friend WithEvents chkFilterUnits As System.Windows.Forms.CheckBox
    Friend WithEvents chkFilterObjectives As System.Windows.Forms.CheckBox

#Region "Filters"
    Private Sub chkFilterObjectives_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkFilterObjectives.CheckedChanged
        If chkFilterObjectives.Checked = True Then
            filterParam += SHOWOBJECTIVES
        Else
            filterParam -= SHOWOBJECTIVES
        End If
        ListItems()

    End Sub

    Private Sub chkFilterUnits_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkFilterUnits.CheckedChanged
        If chkFilterUnits.Checked = True Then
            filterParam += SHOWUNITS
        Else
            filterParam -= SHOWUNITS
        End If
        ListItems()
    End Sub

    Private Sub chkFilterTokens_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkFilterTokens.CheckedChanged
        If chkFilterTokens.Checked = True Then
            filterParam += SHOWTOKENS
        Else
            filterParam -= SHOWTOKENS
        End If
        ListItems()
    End Sub

    Private Sub chkFilterRules_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkFilterRules.CheckedChanged
        If chkFilterRules.Checked = True Then
            filterParam += SHOWRULES
        Else
            filterParam -= SHOWRULES
        End If
        ListItems()
    End Sub

    Private Sub chkFilterResources_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkFilterResources.CheckedChanged
        If chkFilterResources.Checked = True Then
            filterParam += SHOWRESOURCES
        Else
            filterParam -= SHOWRESOURCES
        End If
        ListItems()
    End Sub

    'Private Sub chkFilterOrders_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkFilterOrders.CheckedChanged
    '    If chkFilterOrders.Checked = True Then
    '        filterParam += SHOWORDERS
    '    Else
    '        filterParam -= SHOWORDERS
    '    End If
    '    ListItems()
    'End Sub
#End Region

    Private Sub lstObjects_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstObjects.SelectedIndexChanged
        Try
            ' TODO: determine type of object selected and allow for editing of that object (so we can show/edit the item)
            Dim key As String
            ' clear selected item color

            If lstObjects.SelectedItems.Count = 0 Then Exit Sub

            'key = lstObjects.SelectedItems(0).Text

            Dim selCItem As CampaignerListViewItem = DirectCast(lstObjects.SelectedItems(0), CampaignerListViewItem)

            RaiseEvent ItemSelected(selCItem.obj, selCItem.CampaignerObjectType)

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub lstObjects_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstObjects.MouseMove
        'TODO: Implement Drag and Drop

        ' exit if no button is pressed
        If e.Button = 0 Then Exit Sub

    End Sub

    Private Sub lstObjects_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstObjects.DoubleClick
        Try
            If lstObjects.SelectedItems Is Nothing Then Exit Sub

            Dim selCItem As CampaignerListViewItem = DirectCast(lstObjects.SelectedItems(0), CampaignerListViewItem)

            RaiseEvent ItemDoubleClicked(selCItem.obj, selCItem.CampaignerObjectType)

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub lstObjects_SelectedIndexChanged1(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstObjects.SelectedIndexChanged
        Try
            If lstObjects.SelectedItems Is Nothing Then Exit Sub
            If lstObjects.SelectedItems.Count = 0 Then Exit Sub

            Dim selCItem As CampaignerListViewItem = DirectCast(lstObjects.SelectedItems(0), CampaignerListViewItem)

            pgdItem.SelectedObject = selCItem.obj

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub
End Class




Public Class CampaignerListViewItem : Inherits ListViewItem
    Private _type As CampaignerObjectType_cot = CampaignerObjectType_cot.noItem '// this is what we default to.
    Private _obj As Object '// whatever it is, here it is.

    Public Property CampaignerObjectType() As CampaignerObjectType_cot
        Get
            Return _type
        End Get
        Set(ByVal value As CampaignerObjectType_cot)
            _type = value
        End Set
    End Property

    Public Property obj() As Object
        Get
            Return _obj
        End Get
        Set(ByVal value As Object)
            _obj = value
        End Set
    End Property

End Class